<?php
/**
 * Created by Account.php.
 * User: wy
 * Date: 2019/4/29
 * Time: 9:46
 */

namespace app\admin\controller;


use think\Cache;
use think\Db;

class Account extends Base
{
    public function index(){
        $config = Cache::get('config');
        if(empty($config)){
            $config = [];
            //顺风车用户消费总览
            $fr_pay = [];
            $fr_pay['alipay'] = sprintf('%.2f',(Db::table('fr_order_common')->where("pay_tool",1)->sum('need_price'))/100);//支付宝消费
            $fr_pay['wx'] = sprintf('%.2f',(Db::table('fr_order_common')->where("pay_tool",2)->sum('need_price'))/100);//微信消费
            $fr_pay['balance'] = sprintf('%.2f',(Db::table('fr_order_common')->where("pay_tool",3)->sum('need_price'))/100);//余额消费
            $fr_pay['coupon'] = sprintf('%.2f',Db::table('fr_order_common')->where("is_pay",1)->sum('coupon_price')/100);//优惠券消费
            $config['fr_pay'] = $fr_pay;

            //顺风车订单总览
            $fr_order = [];
            $fr_order_common = Db::query('SELECT SUM(original_price) as original_price,sum(need_price) as need_price,sum(platform_price) as platform_price,sum(thank_price) as thank_price,sum(coupon_price) as coupon_price,sum(platform_price) as platform_price FROM fr_order_common WHERE is_pay=1');
            $fr_order['original_price'] = sprintf('%.2f',$fr_order_common[0]['original_price']/100);//已完成订单总金额
            $fr_order['need_price_dec'] = sprintf('%.2f',($fr_order_common[0]['need_price']-$fr_order_common[0]['platform_price'])/100);//顺风车主收入总额
            $fr_order['need_price'] = sprintf('%.2f',$fr_order_common[0]['need_price']/100);//实付金额
            $fr_order['thank_price'] = sprintf('%.2f',$fr_order_common[0]['thank_price']/100);//感谢费金额
            $fr_order['coupon_price'] = sprintf('%.2f',$fr_order_common[0]['coupon_price']/100);//优惠总金额
            $fr_order['platform_price'] = sprintf('%.2f',$fr_order_common[0]['platform_price']/100);//平台费用
            $fr_order['refund_money'] = sprintf('%.2f',(Db::table('fr_refund')->where("is_pay",1)->sum('refund_money'))/100);//订单退款
            $config['fr_order'] = $fr_order;

            //城际订单总览
            $xm_order = [];
            $xm_order_common = Db::query('SELECT SUM(original_price) as original_price,sum(need_price) as need_price,sum(platform_price) as platform_price,SUM(coupon_price) as coupon_price FROM xm_order_common WHERE order_status IN(45,50)');
            $xm_order['original_price'] = sprintf('%.2f',$xm_order_common[0]['original_price']/100);//已完成订单总金额
            $xm_order['need_price_dec'] = sprintf('%.2f',($xm_order_common[0]['need_price']-$xm_order_common[0]['platform_price'])/100);//司机收入总额
            $xm_order['need_price'] = sprintf('%.2f',$xm_order_common[0]['need_price']/100);//实付金额
            $xm_order['coupon_price'] = sprintf('%.2f',$xm_order_common[0]['coupon_price']/100);//优惠总金额
            $xm_order['platform_price'] = sprintf('%.2f',$xm_order_common[0]['platform_price']/100);//平台费用
            $xm_order['refund_money'] = sprintf('%.2f',(Db::table('inter_refund')->where("is_handle",1)->sum('refund_money'))/100);//订单退款
            $xm_order['driver_cash'] = sprintf('%.2f',(Db::table('xm_driver_wallet_record')->where(" is_pay",1)->sum('money'))/100);//司机提现金额
            $config['xm_order'] = $xm_order;

            //用户钱包监控
            $user_wallet = [];
            $user_wallet['wallet_money'] = sprintf('%.2f',(Db::table('xm_user_wallet')->sum('wallet_money'))/100);//当前钱包总额
            $user_wallet['cash'] = sprintf('%.2f',abs(Db::table('xm_user_recharge')->where(['money_statement'=>10,'status'=>1])->sum('money'))/100);//已提现总额
            $user_wallet['alipay'] = sprintf('%.2f',(Db::table('xm_user_recharge')->where(['type'=>1,'money_statement'=>1,'STATUS'=>1])->sum('money'))/100);//支付宝充值
            $user_wallet['wx'] = sprintf('%.2f',(Db::table('xm_user_recharge')->where(['type'=>2,'money_statement'=>1,'STATUS'=>1])->sum('money'))/100);//微信充值
            $user_wallet['refund'] = $fr_order['refund_money']+$xm_order['refund_money']; //订单退款
            $user_wallet['commission'] = sprintf('%.2f',(Db::table('xm_member_recharge')->where("type",3)->sum('money'))/100);//佣金转入
            $config['user_wallet'] = $user_wallet;

            Cache::set('config',$config,86400);
        }
        $this->assign($config);
        return $this->fetch();
    }
}